# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an

"""
Pyqt在等待线程执行完毕才能进行下一步，过程可能会造成界面卡顿。
不断的刷新则给人感觉运行顺畅

"""
import time

from PyQt5.QtWidgets import *
import sys


class Event(QWidget):
    def __init__(self):
        super(Event, self).__init__()

        self.setWindowTitle("实时刷新页面例子")
        self.listFile = QListWidget()
        self.btnStart = QPushButton("开始")
        layout = QGridLayout()
        layout.addWidget(self.listFile,0,0,1,2)
        layout.addWidget(self.btnStart,1,1)

        self.btnStart.clicked.connect(self.slotAdd)
        self.setLayout(layout)

    def slotAdd(self):
        for i in range(10):
            str_n = "File index {}".format(i)
            self.listFile.addItem(str_n)
            QApplication.processEvents()
            time.sleep(1)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ev = Event()
    ev.show()
    sys.exit(app.exec_())
